package org.jivesoftware.smack.util;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.packet.Authentication;
import org.jivesoftware.smack.packet.Bind;
import org.jivesoftware.smack.packet.DefaultPacketExtension;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Message.Type;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.smack.packet.RosterPacket;
import org.jivesoftware.smack.packet.RosterPacket.Item;
import org.jivesoftware.smack.packet.RosterPacket.ItemStatus;
import org.jivesoftware.smack.packet.RosterPacket.ItemType;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.packet.XMPPError.Condition;
import org.jivesoftware.smack.packet.XMPPError.Type;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.sasl.SASLMechanism.Failure;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class PacketParserUtils
{
  private static final String PROPERTIES_NAMESPACE = "http://www.jivesoftware.com/xmlns/xmpp/properties";

  private static Object decode(Class paramClass, String paramString)
    throws Exception
  {
    Object localObject;
    if (paramClass.getName().equals("java.lang.String"))
      localObject = paramString;
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  return localObject;
                  if (!(paramClass.getName().equals("boolean")))
                    break;
                  localObject = Boolean.valueOf(paramString);
                }
                if (!(paramClass.getName().equals("int")))
                  break;
                localObject = Integer.valueOf(paramString);
              }
              if (!(paramClass.getName().equals("long")))
                break;
              localObject = Long.valueOf(paramString);
            }
            if (!(paramClass.getName().equals("float")))
              break;
            localObject = Float.valueOf(paramString);
          }
          if (!(paramClass.getName().equals("double")))
            break;
          localObject = Double.valueOf(paramString);
        }
        if (!(paramClass.getName().equals("java.lang.Class")))
          break;
        localObject = Class.forName(paramString);
      }
      localObject = null;
    }
  }

  private static String getLanguageAttribute(XmlPullParser paramXmlPullParser)
  {
    int i = 0;
    while (true)
    {
      String str2;
      if (i >= paramXmlPullParser.getAttributeCount())
        str2 = null;
      while (true)
      {
        return str2;
        String str1 = paramXmlPullParser.getAttributeName(i);
        if ((!("xml:lang".equals(str1))) && (((!("lang".equals(str1))) || (!("xml".equals(paramXmlPullParser.getAttributePrefix(i)))))))
          break;
        str2 = paramXmlPullParser.getAttributeValue(i);
      }
      ++i;
    }
  }

  private static Authentication parseAuthentication(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    Authentication localAuthentication = new Authentication();
    int i = 0;
    while (true)
    {
      int j;
      label136: 
      do
        while (true)
        {
          do
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  if (i != 0)
                    return localAuthentication;
                  j = paramXmlPullParser.next();
                  if (j != 2)
                    break label136;
                  if (!(paramXmlPullParser.getName().equals("username")))
                    break;
                  localAuthentication.setUsername(paramXmlPullParser.nextText());
                }
                if (!(paramXmlPullParser.getName().equals("password")))
                  break;
                localAuthentication.setPassword(paramXmlPullParser.nextText());
              }
              if (!(paramXmlPullParser.getName().equals("digest")))
                break;
              localAuthentication.setDigest(paramXmlPullParser.nextText());
            }
          while (!(paramXmlPullParser.getName().equals("resource")));
          localAuthentication.setResource(paramXmlPullParser.nextText());
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("query"))));
      i = 1;
    }
  }

  public static Collection<String> parseCompressionMethods(XmlPullParser paramXmlPullParser)
    throws IOException, XmlPullParserException
  {
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    while (true)
    {
      int j;
      label58: 
      do
        while (true)
        {
          do
          {
            if (i != 0)
              return localArrayList;
            j = paramXmlPullParser.next();
            if (j != 2)
              break label58;
          }
          while (!(paramXmlPullParser.getName().equals("method")));
          localArrayList.add(paramXmlPullParser.nextText());
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("compression"))));
      i = 1;
    }
  }

  private static String parseContent(XmlPullParser paramXmlPullParser)
    throws XmlPullParserException, IOException
  {
    String str = "";
    int i = paramXmlPullParser.getDepth();
    while (true)
    {
      if ((paramXmlPullParser.next() == 3) && (paramXmlPullParser.getDepth() == i))
        return str;
      str = str + paramXmlPullParser.getText();
    }
  }

  public static XMPPError parseError(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    int j;
    Object localObject2;
    String str1 = "-1";
    String str2 = null;
    String str3 = null;
    Object localObject1 = null;
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    if (i >= paramXmlPullParser.getAttributeCount())
    {
      j = 0;
      if (j == 0)
        break label142;
      localObject2 = XMPPError.Type.CANCEL;
      if (str2 != null);
    }
    try
    {
      label142: int k;
      label232: 
      do
        while (true)
        {
          String str4;
          String str5;
          while (true)
          {
            while (true)
            {
              while (true)
              {
                XMPPError.Type localType = XMPPError.Type.valueOf(str2.toUpperCase());
                localObject2 = localType;
                return new XMPPError(Integer.parseInt(str1), (XMPPError.Type)localObject2, (String)localObject1, str3, localArrayList);
                if (paramXmlPullParser.getAttributeName(i).equals("code"))
                  str1 = paramXmlPullParser.getAttributeValue("", "code");
                if (paramXmlPullParser.getAttributeName(i).equals("type"))
                  str2 = paramXmlPullParser.getAttributeValue("", "type");
                ++i;
              }
              k = paramXmlPullParser.next();
              if (k != 2)
                break label232;
              if (!(paramXmlPullParser.getName().equals("text")))
                break;
              str3 = paramXmlPullParser.nextText();
            }
            str4 = paramXmlPullParser.getName();
            str5 = paramXmlPullParser.getNamespace();
            if (!("urn:ietf:params:xml:ns:xmpp-stanzas".equals(str5)))
              break;
            localObject1 = str4;
          }
          localArrayList.add(parsePacketExtension(str4, str5, paramXmlPullParser));
        }
      while ((k != 3) || (!(paramXmlPullParser.getName().equals("error"))));
      j = 1;
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      while (true)
        localIllegalArgumentException.printStackTrace();
    }
  }

  public static IQ parseIQ(XmlPullParser paramXmlPullParser, Connection paramConnection)
    throws Exception
  {
    Object localObject3;
    Object localObject1 = null;
    String str1 = paramXmlPullParser.getAttributeValue("", "id");
    String str2 = paramXmlPullParser.getAttributeValue("", "to");
    String str3 = paramXmlPullParser.getAttributeValue("", "from");
    IQ.Type localType = IQ.Type.fromString(paramXmlPullParser.getAttributeValue("", "type"));
    XMPPError localXMPPError = null;
    int i = 0;
    if (i != 0)
    {
      if (localObject1 != null)
        break label414;
      if ((IQ.Type.GET != localType) && (IQ.Type.SET != localType))
        break label406;
      1 local1 = new IQ()
      {
        public String getChildElementXML()
        {
          return null;
        }
      };
      local1.setPacketID(str1);
      local1.setTo(str3);
      local1.setFrom(str2);
      local1.setType(IQ.Type.ERROR);
      local1.setError(new XMPPError(XMPPError.Condition.feature_not_implemented));
      paramConnection.sendPacket(local1);
      localObject3 = null;
    }
    while (true)
    {
      while (true)
      {
        int j;
        label379: 
        do
          while (true)
          {
            String str4;
            Object localObject2;
            do
              while (true)
              {
                do
                {
                  String str5;
                  while (true)
                  {
                    while (true)
                    {
                      while (true)
                      {
                        while (true)
                        {
                          while (true)
                          {
                            return localObject3;
                            j = paramXmlPullParser.next();
                            if (j != 2)
                              break label379;
                            str4 = paramXmlPullParser.getName();
                            str5 = paramXmlPullParser.getNamespace();
                            if (!(str4.equals("error")))
                              break;
                            localXMPPError = parseError(paramXmlPullParser);
                          }
                          if ((!(str4.equals("query"))) || (!(str5.equals("jabber:iq:auth"))))
                            break;
                          localObject1 = parseAuthentication(paramXmlPullParser);
                        }
                        if ((!(str4.equals("query"))) || (!(str5.equals("jabber:iq:roster"))))
                          break;
                        localObject1 = parseRoster(paramXmlPullParser);
                      }
                      if ((!(str4.equals("query"))) || (!(str5.equals("jabber:iq:register"))))
                        break;
                      localObject1 = parseRegistration(paramXmlPullParser);
                    }
                    if ((!(str4.equals("bind"))) || (!(str5.equals("urn:ietf:params:xml:ns:xmpp-bind"))))
                      break;
                    localObject1 = parseResourceBinding(paramXmlPullParser);
                  }
                  localObject2 = ProviderManager.getInstance().getIQProvider(str4, str5);
                }
                while (localObject2 == null);
                if (!(localObject2 instanceof IQProvider))
                  break;
                localObject1 = ((IQProvider)localObject2).parseIQ(paramXmlPullParser);
              }
            while (!(localObject2 instanceof Class));
            localObject1 = (IQ)parseWithIntrospection(str4, (Class)localObject2, paramXmlPullParser);
          }
        while ((j != 3) || (!(paramXmlPullParser.getName().equals("iq"))));
        i = 1;
      }
      label406: localObject1 = new IQ()
      {
        public String getChildElementXML()
        {
          return null;
        }
      };
      label414: ((IQ)localObject1).setPacketID(str1);
      ((IQ)localObject1).setTo(str2);
      ((IQ)localObject1).setFrom(str3);
      ((IQ)localObject1).setType(localType);
      ((IQ)localObject1).setError(localXMPPError);
      localObject3 = localObject1;
    }
  }

  public static Collection<String> parseMechanisms(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    while (true)
    {
      int j;
      label59: 
      do
        while (true)
        {
          do
          {
            if (i != 0)
              return localArrayList;
            j = paramXmlPullParser.next();
            if (j != 2)
              break label59;
          }
          while (!(paramXmlPullParser.getName().equals("mechanism")));
          localArrayList.add(paramXmlPullParser.nextText());
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("mechanisms"))));
      i = 1;
    }
  }

  public static Packet parseMessage(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    String str3;
    Map localMap;
    String str4;
    int i;
    String str5;
    String str6;
    String str10;
    String str11;
    Iterator localIterator;
    Message localMessage = new Message();
    String str1 = paramXmlPullParser.getAttributeValue("", "id");
    if (str1 == null)
      str1 = "ID_NOT_AVAILABLE";
    localMessage.setPacketID(str1);
    localMessage.setTo(paramXmlPullParser.getAttributeValue("", "to"));
    localMessage.setFrom(paramXmlPullParser.getAttributeValue("", "from"));
    localMessage.setType(Message.Type.fromString(paramXmlPullParser.getAttributeValue("", "type")));
    String str2 = getLanguageAttribute(paramXmlPullParser);
    if ((str2 != null) && (!("".equals(str2.trim()))))
    {
      localMessage.setLanguage(str2);
      str3 = str2;
    }
    while (true)
    {
      localMap = null;
      str4 = null;
      i = 0;
      if (i == 0)
        break;
      localMessage.setThread(str4);
      if (localMap != null)
      {
        localIterator = localMap.keySet().iterator();
        if (localIterator.hasNext())
          break label421;
      }
      return localMessage;
      str3 = Packet.getDefaultLanguage();
    }
    int j = paramXmlPullParser.next();
    if (j == 2)
    {
      str5 = paramXmlPullParser.getName();
      str6 = paramXmlPullParser.getNamespace();
      if (str5.equals("subject"))
      {
        str10 = getLanguageAttribute(paramXmlPullParser);
        if (str10 != null)
          break label458;
        str11 = str3;
      }
    }
    while (true)
    {
      String str7;
      String str8;
      while (true)
      {
        String str12;
        do
          str12 = parseContent(paramXmlPullParser);
        while (localMessage.getSubject(str11) != null);
        localMessage.addSubject(str11, str12);
      }
      if (str5.equals("body"))
      {
        str7 = getLanguageAttribute(paramXmlPullParser);
        if (str7 != null)
          break label451;
        str8 = str3;
      }
      while (true)
      {
        while (true)
        {
          while (true)
          {
            do
              while (true)
              {
                while (true)
                {
                  while (true)
                  {
                    while (true)
                    {
                      do
                      {
                        while (true)
                        {
                          String str9;
                          do
                            str9 = parseContent(paramXmlPullParser);
                          while (localMessage.getBody(str8) != null);
                          localMessage.addBody(str8, str9);
                        }
                        if (!(str5.equals("thread")))
                          break label328;
                      }
                      while (str4 != null);
                      str4 = paramXmlPullParser.nextText();
                    }
                    label328: if (!(str5.equals("error")))
                      break;
                    localMessage.setError(parseError(paramXmlPullParser));
                  }
                  if ((!(str5.equals("properties"))) || (!(str6.equals("http://www.jivesoftware.com/xmlns/xmpp/properties"))))
                    break;
                  localMap = parseProperties(paramXmlPullParser);
                }
                localMessage.addExtension(parsePacketExtension(str5, str6, paramXmlPullParser));
              }
            while ((j != 3) || (!(paramXmlPullParser.getName().equals("message"))));
            i = 1;
          }
          label421: String str13 = (String)localIterator.next();
          localMessage.setProperty(str13, localMap.get(str13));
        }
        label451: str8 = str7;
      }
      label458: str11 = str10;
    }
  }

  public static PacketExtension parsePacketExtension(String paramString1, String paramString2, XmlPullParser paramXmlPullParser)
    throws Exception
  {
    Object localObject2;
    Object localObject1 = ProviderManager.getInstance().getExtensionProvider(paramString1, paramString2);
    if (localObject1 != null)
    {
      if (localObject1 instanceof PacketExtensionProvider)
        localObject2 = ((PacketExtensionProvider)localObject1).parseExtension(paramXmlPullParser);
      while (true)
      {
        return localObject2;
        if (!(localObject1 instanceof Class))
          break;
        localObject2 = (PacketExtension)parseWithIntrospection(paramString1, (Class)localObject1, paramXmlPullParser);
      }
    }
    DefaultPacketExtension localDefaultPacketExtension = new DefaultPacketExtension(paramString1, paramString2);
    int i = 0;
    while (true)
    {
      int j;
      label154: 
      do
        while (true)
        {
          String str;
          do
            while (true)
            {
              while (i != 0)
                localObject2 = localDefaultPacketExtension;
              j = paramXmlPullParser.next();
              if (j != 2)
                break label154;
              str = paramXmlPullParser.getName();
              if (!(paramXmlPullParser.isEmptyElementTag()))
                break;
              localDefaultPacketExtension.setValue(str, "");
            }
          while (paramXmlPullParser.next() != 4);
          localDefaultPacketExtension.setValue(str, paramXmlPullParser.getText());
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals(paramString1))));
      i = 1;
    }
  }

  public static Presence parsePresence(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    Presence.Type localType2;
    Presence localPresence;
    String str2;
    String str3;
    int i;
    Presence.Type localType1 = Presence.Type.available;
    String str1 = paramXmlPullParser.getAttributeValue("", "type");
    if ((str1 != null) && (!(str1.equals(""))));
    try
    {
      Presence.Type localType3 = Presence.Type.valueOf(str1);
      localType2 = localType3;
      localPresence = new Presence(localType2);
      localPresence.setTo(paramXmlPullParser.getAttributeValue("", "to"));
      localPresence.setFrom(paramXmlPullParser.getAttributeValue("", "from"));
      str2 = paramXmlPullParser.getAttributeValue("", "id");
      if (str2 == null)
      {
        str3 = "ID_NOT_AVAILABLE";
        localPresence.setPacketID(str3);
        String str4 = getLanguageAttribute(paramXmlPullParser);
        if ((str4 != null) && (!("".equals(str4.trim()))))
          localPresence.setLanguage(str4);
        if (str2 == null)
          str2 = "ID_NOT_AVAILABLE";
        localPresence.setPacketID(str2);
        i = 0;
        if (i == 0)
          break label202;
        label202: label482: return localPresence;
      }
    }
    catch (IllegalArgumentException localIllegalArgumentException3)
    {
      int j;
      String str5;
      String str6;
      while (true)
      {
        while (true)
        {
          while (true)
          {
            System.err.println("Found invalid presence type " + str1);
            localType2 = localType1;
          }
          str3 = str2;
        }
        j = paramXmlPullParser.next();
        if (j != 2)
          break label482;
        str5 = paramXmlPullParser.getName();
        str6 = paramXmlPullParser.getNamespace();
        if (!(str5.equals("status")))
          break;
        localPresence.setStatus(paramXmlPullParser.nextText());
      }
      if (str5.equals("priority"));
      try
      {
        localPresence.setPriority(Integer.parseInt(paramXmlPullParser.nextText()));
      }
      catch (NumberFormatException localNumberFormatException)
      {
      }
      catch (IllegalArgumentException localIllegalArgumentException2)
      {
        String str8;
        while (true)
          localPresence.setPriority(0);
        if (str5.equals("show"))
          str8 = paramXmlPullParser.nextText();
        try
        {
          localPresence.setMode(Presence.Mode.valueOf(str8));
        }
        catch (IllegalArgumentException localIllegalArgumentException1)
        {
          do
            while (true)
            {
              while (true)
              {
                while (true)
                  System.err.println("Found invalid presence mode " + str8);
                if (!(str5.equals("error")))
                  break;
                localPresence.setError(parseError(paramXmlPullParser));
              }
              if ((str5.equals("properties")) && (str6.equals("http://www.jivesoftware.com/xmlns/xmpp/properties")))
              {
                Map localMap = parseProperties(paramXmlPullParser);
                Iterator localIterator = localMap.keySet().iterator();
                while (true)
                {
                  if (!(localIterator.hasNext()));
                  String str7 = (String)localIterator.next();
                  localPresence.setProperty(str7, localMap.get(str7));
                }
              }
              localPresence.addExtension(parsePacketExtension(str5, str6, paramXmlPullParser));
            }
          while ((j != 3) || (!(paramXmlPullParser.getName().equals("presence"))));
          i = 1;
        }
      }
    }
  }

  public static Map<String, Object> parseProperties(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    String str1;
    Object localObject1;
    Object localObject3;
    HashMap localHashMap = new HashMap();
    int i = paramXmlPullParser.next();
    if ((i == 2) && (paramXmlPullParser.getName().equals("property")))
    {
      int k;
      int j = 0;
      str1 = null;
      localObject1 = null;
      Object localObject2 = null;
      String str2 = null;
      while (true)
      {
        String str3;
        while (true)
        {
          if (j != 0);
          k = paramXmlPullParser.next();
          if (k != 2)
            break label135;
          str3 = paramXmlPullParser.getName();
          if (!(str3.equals("name")))
            break;
          str2 = paramXmlPullParser.nextText();
        }
        if (!(str3.equals("value")))
          break label380;
        String str4 = paramXmlPullParser.getAttributeValue("", "type");
        str1 = paramXmlPullParser.nextText();
        localObject2 = str4;
      }
      label135: if ((k != 3) || (!(paramXmlPullParser.getName().equals("property"))))
        break label380;
      if ("integer".equals(localObject2))
        localObject3 = Integer.valueOf(str1);
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  if ((str2 != null) && (localObject3 != null))
                    localHashMap.put(str2, localObject3);
                  j = 1;
                  localObject1 = localObject3;
                }
                if (!("long".equals(localObject2)))
                  break;
                localObject3 = Long.valueOf(str1);
              }
              if (!("float".equals(localObject2)))
                break;
              localObject3 = Float.valueOf(str1);
            }
            if (!("double".equals(localObject2)))
              break;
            localObject3 = Double.valueOf(str1);
          }
          if (!("boolean".equals(localObject2)))
            break;
          localObject3 = Boolean.valueOf(str1);
        }
        if (!("string".equals(localObject2)))
          break;
        localObject3 = str1;
      }
      if ("java-object".equals(localObject2));
    }
    try
    {
      Object localObject4 = new ObjectInputStream(new ByteArrayInputStream(StringUtils.decodeBase64(str1))).readObject();
      label380: localObject3 = localObject4;
    }
    catch (Exception localException)
    {
      while (true)
      {
        do
          while (true)
          {
            localException.printStackTrace();
            localObject3 = localObject1;
          }
        while ((i != 3) || (!(paramXmlPullParser.getName().equals("properties"))));
        return localHashMap;
      }
    }
  }

  private static Registration parseRegistration(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    Registration localRegistration = new Registration();
    int i = 0;
    while (true)
    {
      int j;
      label100: label123: 
      do
        while (true)
        {
          while (true)
          {
            String str1;
            String str2;
            while (true)
            {
              do
              {
                if (i != 0)
                  return localRegistration;
                j = paramXmlPullParser.next();
                if (j != 2)
                  break label123;
                if (!(paramXmlPullParser.getNamespace().equals("jabber:iq:register")))
                  break label100;
                str1 = paramXmlPullParser.getName();
              }
              while (paramXmlPullParser.next() != 4);
              str2 = paramXmlPullParser.getText();
              if (!(str1.equals("instructions")))
                break;
              localRegistration.setInstructions(str2);
            }
            localRegistration.addAttribute(str1, str2);
          }
          localRegistration.addExtension(parsePacketExtension(paramXmlPullParser.getName(), paramXmlPullParser.getNamespace(), paramXmlPullParser));
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("query"))));
      i = 1;
    }
  }

  private static Bind parseResourceBinding(XmlPullParser paramXmlPullParser)
    throws IOException, XmlPullParserException
  {
    Bind localBind = new Bind();
    int i = 0;
    while (true)
    {
      int j;
      label83: 
      do
        while (true)
        {
          do
            while (true)
            {
              if (i != 0)
                return localBind;
              j = paramXmlPullParser.next();
              if (j != 2)
                break label83;
              if (!(paramXmlPullParser.getName().equals("resource")))
                break;
              localBind.setResource(paramXmlPullParser.nextText());
            }
          while (!(paramXmlPullParser.getName().equals("jid")));
          localBind.setJid(paramXmlPullParser.nextText());
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("bind"))));
      i = 1;
    }
  }

  private static RosterPacket parseRoster(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    RosterPacket localRosterPacket = new RosterPacket();
    int i = 0;
    RosterPacket.Item localItem = null;
    while (true)
    {
      do
      {
        int j;
        do
        {
          if (i != 0)
            return localRosterPacket;
          if ((paramXmlPullParser.getEventType() == 2) && (paramXmlPullParser.getName().equals("query")))
            localRosterPacket.setVersion(paramXmlPullParser.getAttributeValue(null, "ver"));
          j = paramXmlPullParser.next();
          if (j == 2)
          {
            String str2;
            if (paramXmlPullParser.getName().equals("item"))
            {
              localItem = new RosterPacket.Item(paramXmlPullParser.getAttributeValue("", "jid"), paramXmlPullParser.getAttributeValue("", "name"));
              localItem.setItemStatus(RosterPacket.ItemStatus.fromString(paramXmlPullParser.getAttributeValue("", "ask")));
              String str1 = paramXmlPullParser.getAttributeValue("", "subscription");
              if (str1 == null)
                break label216;
              str2 = str1;
            }
            while (true)
            {
              while (true)
              {
                String str3;
                do
                {
                  do
                    localItem.setItemType(RosterPacket.ItemType.valueOf(str2));
                  while ((!(paramXmlPullParser.getName().equals("group"))) || (localItem == null));
                  str3 = paramXmlPullParser.nextText();
                }
                while ((str3 == null) || (str3.trim().length() <= 0));
                localItem.addGroupName(str3);
              }
              label216: str2 = "none";
            }
          }
        }
        while (j != 3);
        if (paramXmlPullParser.getName().equals("item"))
          localRosterPacket.addRosterItem(localItem);
      }
      while (!(paramXmlPullParser.getName().equals("query")));
      i = 1;
    }
  }

  public static SASLMechanism.Failure parseSASLFailure(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    String str = null;
    int i = 0;
    while (true)
    {
      int j;
      label54: 
      do
        while (true)
        {
          do
          {
            if (i != 0)
              return new SASLMechanism.Failure(str);
            j = paramXmlPullParser.next();
            if (j != 2)
              break label54;
          }
          while (paramXmlPullParser.getName().equals("failure"));
          str = paramXmlPullParser.getName();
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("failure"))));
      i = 1;
    }
  }

  public static StreamError parseStreamError(XmlPullParser paramXmlPullParser)
    throws IOException, XmlPullParserException
  {
    StreamError localStreamError = null;
    int i = 0;
    while (true)
    {
      int j;
      do
        while (true)
        {
          if (i != 0)
            return localStreamError;
          j = paramXmlPullParser.next();
          if (j != 2)
            break;
          localStreamError = new StreamError(paramXmlPullParser.getName());
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("error"))));
      i = 1;
    }
  }

  public static Object parseWithIntrospection(String paramString, Class paramClass, XmlPullParser paramXmlPullParser)
    throws Exception
  {
    int i = 0;
    Object localObject1 = paramClass.newInstance();
    while (true)
    {
      int j;
      do
        while (true)
        {
          if (i != 0)
            return localObject1;
          j = paramXmlPullParser.next();
          if (j != 2)
            break;
          String str1 = paramXmlPullParser.getName();
          String str2 = paramXmlPullParser.nextText();
          Class localClass1 = localObject1.getClass().getMethod("get" + Character.toUpperCase(str1.charAt(0)) + str1.substring(1), new Class[0]).getReturnType();
          Object localObject2 = decode(localClass1, str2);
          Class localClass2 = localObject1.getClass();
          String str3 = "set" + Character.toUpperCase(str1.charAt(0)) + str1.substring(1);
          Class[] arrayOfClass = new Class[1];
          arrayOfClass[0] = localClass1;
          Method localMethod = localClass2.getMethod(str3, arrayOfClass);
          Object[] arrayOfObject = new Object[1];
          arrayOfObject[0] = localObject2;
          localMethod.invoke(localObject1, arrayOfObject);
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals(paramString))));
      i = 1;
    }
  }
}